import { configureStore, ThunkAction, Action, combineReducers } from "@reduxjs/toolkit";
import userReducer from "./user/userSlice";
import languageReducer from './language/languageReducer'

import logger from 'redux-logger'

import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web

const persistConfig = {
  key: 'root11',
  storage,
}

const rootReducer = combineReducers({
  user: userReducer,
  language: languageReducer,
})
const persistedReducer = persistReducer(persistConfig, rootReducer)

export const store = configureStore({
  reducer: persistedReducer,
  // middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: false, }).concat(logger),
});

export const persistor = persistStore(store)

export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
export type AppThunk<ReturnType = void> = ThunkAction<
  ReturnType,
  RootState,
  unknown,
  Action<string>
>;


